home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Everything / Checkboxes.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  13.4 KB  |  559 lines  |  [TEXT/CWIE]

  1. { Checkboxes.p }
  2. { Created 10/30/98 1:06 PM by AppMaker }
  3.  
  4. Unit Checkboxes;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     EverythingEngine,
  21.     EverythingDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     Checkboxes        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mStandard2Handle:        ControlHandle;
  30.         mXxHandle:        ControlHandle;
  31.         mCapTriangleLabel:    ControlHandle;
  32.         mGraphic2Handle:        ControlHandle;
  33.         mCapcicn2Label:    ControlHandle;
  34.         mLRHandle:        ControlHandle;
  35.         mCapicl10Label:    ControlHandle;
  36.         mLR2Handle:        ControlHandle;
  37.         mCapICN2Label:    ControlHandle;
  38.         mLR3Handle:        ControlHandle;
  39.         mCapPICT2Label:    ControlHandle;
  40.         mLR4Handle:        ControlHandle;
  41.         mCheckboxHandle:        ControlHandle;
  42.         mCapicl11Label:    ControlHandle;
  43.         mBevel2Handle:        ControlHandle;
  44.         mCheckbox2Handle:        ControlHandle;
  45.         mNext3Handle:        ControlHandle;
  46.         mNext4Handle:        ControlHandle;
  47.  
  48.     {methods}
  49.         Procedure Initialize; Override;
  50.  
  51.         Procedure Open        (inDoc:        EverythingDoc;
  52.                              inData:    DDocData);
  53.         Procedure Close; Override;
  54.  
  55.         Procedure Control    (whichControl:    ControlHandle;
  56.                               whichPart:        integer;
  57.                              where:            Point); Override;
  58.         Procedure MouseIn    (where:            Point;
  59.                              modifiers:        integer); Override;
  60.         Procedure TypeIn    (charCode:        SInt16); Override;
  61.         Procedure ExitCurField; Override;
  62.         Procedure DataChanged    (inDataID:    longint); Override;
  63.         Procedure Resize; Override;
  64.         Procedure Scroll    (newValue:        integer;
  65.                              oldValue:        integer); Override;
  66.  
  67.         Function  GetEngine: EverythingEngine;
  68.  
  69. {$ifc false}
  70.         Procedure UpdateMenus; Override;
  71. {$endif}
  72.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  73.  
  74.         Procedure DoUndo;
  75.         Procedure DoCut;
  76.         Procedure DoCopy;
  77.         Procedure DoPaste;
  78.         Procedure DoClear;
  79.         Procedure DoSelectAll;
  80.         Procedure DoShowClipboard;
  81.  
  82.     end;
  83.  
  84. {----------}
  85. Procedure CreateCheckboxes    (inDoc:        EverythingDoc;
  86.                              inData:    DDocData);
  87.  
  88. {----------}
  89. Implementation
  90.  
  91. Uses
  92.     Globals,
  93.     ResourceDefs,
  94.     DoScrap,
  95.     Scrolling,
  96.     ControlUtils,
  97.     Miscellany;
  98.  
  99. const
  100.     kStandard2Check        = 1;
  101.     kXxCheck        = 2;
  102.     kCapTriangleLabel        = 3;
  103.     kGraphic2Box        = 4;
  104.     kCapcicn2Label        = 5;
  105.     kLRCheck        = 6;
  106.     kCapicl10Label        = 7;
  107.     kLR2Check        = 8;
  108.     kCapICN2Label        = 9;
  109.     kLR3Check        = 10;
  110.     kCapPICT2Label        = 11;
  111.     kLR4Check        = 12;
  112.     kCheckboxCheck        = 13;
  113.     kCapicl11Label        = 14;
  114.     kBevel2Box        = 15;
  115.     kCheckbox2Check        = 16;
  116.     kNext3Check        = 17;
  117.     kNext4Check        = 18;
  118.  
  119. {----------}
  120. Procedure CreateCheckboxes (
  121.     inDoc:        EverythingDoc;
  122.     inData:        DDocData);
  123. var
  124.     winObj:        Checkboxes;
  125. begin
  126.     winObj := nil;
  127.     New (winObj);
  128.  
  129.     if winObj <> nil then begin
  130.         winObj.Initialize;
  131.         winObj.Open (inDoc, inData);
  132.     end;
  133. end;
  134.  
  135. {----------}
  136. Procedure Checkboxes.Initialize;
  137. begin
  138.     Inherited Initialize;
  139. end;
  140.  
  141. {----------}
  142. Function  Checkboxes.GetEngine: EverythingEngine;
  143. begin
  144.     GetEngine := EverythingEngine (mDoc.mEngine);
  145. end;
  146.  
  147. {----------}
  148. Procedure Checkboxes.Open (
  149.     inDoc:        EverythingDoc;
  150.     inData:        DDocData);
  151. var
  152.     window:        WindowPtr;
  153.     wftb:        Handle;
  154.     errCode:    OSErr;
  155. begin
  156.     mDoc := inDoc;
  157.     mData := inData;
  158.     mData.AddResponder (self);
  159.  
  160.     window := GetNewCWindow (WIND_Checkboxes, nil, WindowPtr (-1));
  161.     if inDoc.mEngine.GetFilename <> '' then begin
  162.         SetWTitle (window, inDoc.mEngine.GetFilename);
  163.     end;
  164.     mWindow := window;
  165.     EverythingDoc (mDoc).mCheckboxesPtr := window;
  166.  
  167.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  168.     SetWRefCon (window, ord4 (self));
  169.     SetPort (window);
  170.     SetInfo (window);
  171.  
  172.     wftb := GetResource ('Wftb', WIND_Checkboxes);
  173.  
  174.     errCode := CreateRootControl (window, mRootControl);
  175.  
  176.     vScroll := nil;
  177.     hScroll := nil;
  178.  
  179.  
  180.     mStandard2Handle := GetNewControl (CNTL_Standard2, window);
  181.     SetWindowItemFont (mStandard2Handle, wftb, 1);
  182.     SetControlValue (mStandard2Handle, ord (mData.GetStandard));
  183.  
  184.     mXxHandle := GetNewControl (CNTL_Xx, window);
  185.     SetWindowItemFont (mXxHandle, wftb, 2);
  186.     SetControlValue (mXxHandle, ord (mData.GetXx));
  187.  
  188.     mCapTriangleLabel := GetNewControl (CNTL_CapTriangle, window);
  189.     SetWindowItemFont (mCapTriangleLabel, wftb, 3);
  190.     SetControlFromTEXT (mCapTriangleLabel, TEXT_CapTriangle);
  191.  
  192.     mGraphic2Handle := GetNewControl (CNTL_Graphic2, window);
  193.     SetWindowItemFont (mGraphic2Handle, wftb, 4);
  194.  
  195.     mCapcicn2Label := GetNewControl (CNTL_Capcicn2, window);
  196.     errCode := EmbedControl (mCapcicn2Label, mGraphic2Handle);
  197.     SetWindowItemFont (mCapcicn2Label, wftb, 5);
  198.     SetControlFromTEXT (mCapcicn2Label, TEXT_Capcicn2);
  199.  
  200.     mLRHandle := GetNewControl (CNTL_LR, window);
  201.     errCode := EmbedControl (mLRHandle, mGraphic2Handle);
  202.     SetWindowItemFont (mLRHandle, wftb, 6);
  203.     SetControlValue (mLRHandle, ord (mData.GetLR));
  204.  
  205.     mCapicl10Label := GetNewControl (CNTL_Capicl10, window);
  206.     errCode := EmbedControl (mCapicl10Label, mGraphic2Handle);
  207.     SetWindowItemFont (mCapicl10Label, wftb, 7);
  208.     SetControlFromTEXT (mCapicl10Label, TEXT_Capicl10);
  209.  
  210.     mLR2Handle := GetNewControl (CNTL_LR2, window);
  211.     errCode := EmbedControl (mLR2Handle, mGraphic2Handle);
  212.     SetWindowItemFont (mLR2Handle, wftb, 8);
  213.     SetControlValue (mLR2Handle, ord (mData.GetLR2));
  214.  
  215.     mCapICN2Label := GetNewControl (CNTL_CapICN2, window);
  216.     errCode := EmbedControl (mCapICN2Label, mGraphic2Handle);
  217.     SetWindowItemFont (mCapICN2Label, wftb, 9);
  218.     SetControlFromTEXT (mCapICN2Label, TEXT_CapICN2);
  219.  
  220.     mLR3Handle := GetNewControl (CNTL_LR3, window);
  221.     errCode := EmbedControl (mLR3Handle, mGraphic2Handle);
  222.     SetWindowItemFont (mLR3Handle, wftb, 10);
  223.     SetControlValue (mLR3Handle, ord (mData.GetLR3));
  224.  
  225.     mCapPICT2Label := GetNewControl (CNTL_CapPICT2, window);
  226.     errCode := EmbedControl (mCapPICT2Label, mGraphic2Handle);
  227.     SetWindowItemFont (mCapPICT2Label, wftb, 11);
  228.     SetControlFromTEXT (mCapPICT2Label, TEXT_CapPICT2);
  229.  
  230.     mLR4Handle := GetNewControl (CNTL_LR4, window);
  231.     errCode := EmbedControl (mLR4Handle, mGraphic2Handle);
  232.     SetWindowItemFont (mLR4Handle, wftb, 12);
  233.     SetControlValue (mLR4Handle, ord (mData.GetLR4));
  234.  
  235.     mCheckboxHandle := GetNewControl (CNTL_Checkbox, window);
  236.     errCode := EmbedControl (mCheckboxHandle, mGraphic2Handle);
  237.     SetWindowItemFont (mCheckboxHandle, wftb, 13);
  238.     SetControlValue (mCheckboxHandle, ord (mData.GetCheckbox));
  239.  
  240.     mCapicl11Label := GetNewControl (CNTL_Capicl11, window);
  241.     errCode := EmbedControl (mCapicl11Label, mGraphic2Handle);
  242.     SetWindowItemFont (mCapicl11Label, wftb, 14);
  243.     SetControlFromTEXT (mCapicl11Label, TEXT_Capicl11);
  244.  
  245.     mBevel2Handle := GetNewControl (CNTL_Bevel2, window);
  246.     SetWindowItemFont (mBevel2Handle, wftb, 15);
  247.  
  248.     mCheckbox2Handle := GetNewControl (CNTL_Checkbox2, window);
  249.     errCode := EmbedControl (mCheckbox2Handle, mBevel2Handle);
  250.     SetWindowItemFont (mCheckbox2Handle, wftb, 16);
  251.     SetControlValue (mCheckbox2Handle, ord (mData.GetCheckbox2));
  252.         errCode := SetBevelButtonGraphicAlignment (mCheckbox2Handle, kControlBevelButtonAlignCenter, 0, 0);
  253.  
  254.     mNext3Handle := GetNewControl (CNTL_Next3, window);
  255.     errCode := EmbedControl (mNext3Handle, mBevel2Handle);
  256.     SetWindowItemFont (mNext3Handle, wftb, 17);
  257.     SetControlValue (mNext3Handle, ord (mData.GetNext));
  258.         errCode := SetBevelButtonTextPlacement (mNext3Handle, kControlBevelButtonPlaceToRightOfGraphic);
  259.         errCode := SetBevelButtonTextAlignment (mNext3Handle, kControlBevelButtonAlignTextFlushLeft, 0);
  260.         errCode := SetBevelButtonGraphicAlignment (mNext3Handle, kControlBevelButtonAlignLeft, 0, 0);
  261.  
  262.     mNext4Handle := GetNewControl (CNTL_Next4, window);
  263.     errCode := EmbedControl (mNext4Handle, mBevel2Handle);
  264.     SetWindowItemFont (mNext4Handle, wftb, 18);
  265.     SetControlValue (mNext4Handle, ord (mData.GetNext2));
  266.         errCode := SetBevelButtonTextPlacement (mNext4Handle, kControlBevelButtonPlaceBelowGraphic);
  267.         errCode := SetBevelButtonTextAlignment (mNext4Handle, kControlBevelButtonAlignTextCenter, 0);
  268.         errCode := SetBevelButtonGraphicAlignment (mNext4Handle, kControlBevelButtonAlignTop, 0, 0);
  269.  
  270.     errCode := AdvanceKeyboardFocus (window);
  271.  
  272.     ShowWindow (window);
  273. end;
  274.  
  275. {----------}
  276. Procedure Checkboxes.Close;
  277. begin
  278.     mData.RemoveResponder (self);
  279.  
  280.     EverythingDoc (mDoc).mCheckboxesPtr := nil;
  281.     SetInfo (nil);
  282.     HideWindow (mWindow);
  283.     DisposeWindow (mWindow);
  284.  
  285.     Dispose (self);
  286. end;
  287.  
  288. {----------}
  289. Procedure Checkboxes.Control (
  290.     whichControl:    ControlHandle;
  291.     whichPart:        integer;
  292.     where:            Point);
  293. var
  294.     bounds:            Rect;
  295.     newValue:        integer;
  296.     partcode:        SInt16;
  297. begin
  298.     ExitCurField ();
  299.  
  300.     if whichControl = mStandard2Handle then begin
  301.         if TrackCheckbox (mStandard2Handle, where) then begin
  302.             mData.SetStandard (GetControlValue (mStandard2Handle) <> 0);
  303.         end;
  304.     end;
  305.     if whichControl = mXxHandle then begin
  306.         if TrackCheckbox (mXxHandle, where) then begin
  307.             mData.SetXx (GetControlValue (mXxHandle) <> 0);
  308.         end;
  309.     end;
  310.     if whichControl = mLRHandle then begin
  311.         if TrackCheckbox (mLRHandle, where) then begin
  312.             mData.SetLR (GetControlValue (mLRHandle) <> 0);
  313.         end;
  314.     end;
  315.     if whichControl = mLR2Handle then begin
  316.         if TrackCheckbox (mLR2Handle, where) then begin
  317.             mData.SetLR2 (GetControlValue (mLR2Handle) <> 0);
  318.         end;
  319.     end;
  320.     if whichControl = mLR3Handle then begin
  321.         if TrackCheckbox (mLR3Handle, where) then begin
  322.             mData.SetLR3 (GetControlValue (mLR3Handle) <> 0);
  323.         end;
  324.     end;
  325.     if whichControl = mLR4Handle then begin
  326.         if TrackCheckbox (mLR4Handle, where) then begin
  327.             mData.SetLR4 (GetControlValue (mLR4Handle) <> 0);
  328.         end;
  329.     end;
  330.     if whichControl = mCheckboxHandle then begin
  331.         if TrackCheckbox (mCheckboxHandle, where) then begin
  332.             mData.SetCheckbox (GetControlValue (mCheckboxHandle) <> 0);
  333.         end;
  334.     end;
  335.     if whichControl = mCheckbox2Handle then begin
  336.         if TrackClick (mCheckbox2Handle, where) then begin
  337.             mData.SetCheckbox2 (GetControlValue (mCheckbox2Handle) <> 0);
  338.         end;
  339.     end;
  340.     if whichControl = mNext3Handle then begin
  341.         if TrackClick (mNext3Handle, where) then begin
  342.             mData.SetNext (GetControlValue (mNext3Handle) <> 0);
  343.         end;
  344.     end;
  345.     if whichControl = mNext4Handle then begin
  346.         if TrackClick (mNext4Handle, where) then begin
  347.             mData.SetNext2 (GetControlValue (mNext4Handle) <> 0);
  348.         end;
  349.     end;
  350. end;
  351.  
  352. {----------}
  353. Procedure Checkboxes.DataChanged (
  354.     inDataID:        longint);
  355. begin
  356.     if inDataID = idStandard then begin
  357.         SetControlValue (mStandard2Handle, ord (mData.GetStandard));
  358.     end;
  359.     if inDataID = idXx then begin
  360.         SetControlValue (mXxHandle, ord (mData.GetXx));
  361.     end;
  362.     if inDataID = idLR then begin
  363.         SetControlValue (mLRHandle, ord (mData.GetLR));
  364.     end;
  365.     if inDataID = idLR2 then begin
  366.         SetControlValue (mLR2Handle, ord (mData.GetLR2));
  367.     end;
  368.     if inDataID = idLR3 then begin
  369.         SetControlValue (mLR3Handle, ord (mData.GetLR3));
  370.     end;
  371.     if inDataID = idLR4 then begin
  372.         SetControlValue (mLR4Handle, ord (mData.GetLR4));
  373.     end;
  374.     if inDataID = idCheckbox then begin
  375.         SetControlValue (mCheckboxHandle, ord (mData.GetCheckbox));
  376.     end;
  377.     if inDataID = idCheckbox2 then begin
  378.         SetControlValue (mCheckbox2Handle, ord (mData.GetCheckbox2));
  379.     end;
  380.     if inDataID = idNext then begin
  381.         SetControlValue (mNext3Handle, ord (mData.GetNext));
  382.     end;
  383.     if inDataID = idNext2 then begin
  384.         SetControlValue (mNext4Handle, ord (mData.GetNext2));
  385.     end;
  386. End;
  387.  
  388. {----------}
  389. Procedure Checkboxes.MouseIn (
  390.     where:            Point;
  391.     modifiers:        integer);
  392. var
  393.     bounds:            Rect;
  394. begin
  395. end;
  396.  
  397. {----------}
  398. Procedure Checkboxes.ExitCurField;
  399. var
  400.     errCode:    OSErr;
  401.     focus:        ControlHandle;
  402. begin
  403.     errCode := GetKeyboardFocus (mWindow, focus);
  404.  
  405.     if focus = nil then begin
  406.         { nothing to exit }
  407.  
  408.     end;
  409.     inherited ExitCurField;
  410. end;
  411.  
  412. {----------}
  413. Procedure Checkboxes.TypeIn (
  414.     charCode:    SInt16);
  415. var
  416.     ch:            char;
  417.     errCode:    OSErr;
  418.     focus:        ControlHandle;
  419.     keyCode:    SInt16;
  420.     partcode:    SInt16;
  421. begin
  422.     errCode := GetKeyboardFocus (mWindow, focus);
  423.  
  424.     ch := chr (charCode);
  425.     if (ch = charEnter)
  426.     |  (ch = charReturn) then begin
  427.         ExitCurField;
  428.     end else if ch = charEsc then begin
  429.     end else if ch = charTab then begin
  430.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  431.     end else if focus <> nil then begin
  432.         keyCode := BAnd (curEvent.message, keyCodeMask);
  433.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  434.         mDoc.mEngine.SetDirty;
  435.     end else begin
  436.         SysBeep (1);
  437.     end;
  438. end;
  439.  
  440. {----------}
  441. Procedure Checkboxes.Resize;
  442. begin
  443.     { application-specific code to resize items in window }
  444. end;
  445.  
  446. {----------}
  447. Procedure Checkboxes.Scroll (
  448.     newValue:    integer;
  449.     oldValue:    integer);
  450. begin
  451.     { application-specific code to scroll window }
  452.     if gWhichScroll = vScroll then begin
  453.     end else begin    { horizontal }
  454.     end;
  455. end;
  456.  
  457. {----------}
  458. Procedure Checkboxes.DoUndo;
  459. begin
  460. end; {DoUndo}
  461.  
  462. {----------}
  463. Procedure Checkboxes.DoCut;
  464. var
  465.     curTE:        TEHandle;
  466. begin
  467.     curTE := GetCurTE ();
  468.  
  469.     if curTE <> nil then begin
  470.         TECut (curTE);
  471.         mDoc.mEngine.SetDirty;
  472.         scrapDirty := true;
  473.     end;
  474. end; {DoCut}
  475.  
  476. {----------}
  477. Procedure Checkboxes.DoCopy;
  478. var
  479.     curTE:        TEHandle;
  480. begin
  481.     curTE := GetCurTE ();
  482.  
  483.     if curTE <> nil then begin
  484.         TECopy (curTE);
  485.         scrapDirty := true;
  486.     end;
  487. end; {DoCopy}
  488.  
  489. {----------}
  490. Procedure Checkboxes.DoPaste;
  491. var
  492.     curTE:        TEHandle;
  493. begin
  494.     curTE := GetCurTE ();
  495.  
  496.     if curTE <> nil then begin
  497.         TEPaste (curTE);
  498.         mDoc.mEngine.SetDirty;
  499.     end;
  500. end; {DoPaste}
  501.  
  502. {----------}
  503. Procedure Checkboxes.DoClear;
  504. var
  505.     curTE:        TEHandle;
  506. begin
  507.     curTE := GetCurTE ();
  508.  
  509.     if curTE <> nil then begin
  510.         TEDelete (curTE);
  511.         mDoc.mEngine.SetDirty;
  512.     end;
  513. end; {DoClear}
  514.  
  515. {----------}
  516. Procedure Checkboxes.DoSelectAll;
  517. var
  518.     curTE:        TEHandle;
  519. begin
  520.     curTE := GetCurTE ();
  521.  
  522.     if curTE <> nil then begin
  523.         TESetSelect (0, 32767, curTE);
  524.     end;
  525. end; {DoSelectAll}
  526.  
  527. {----------}
  528. Procedure Checkboxes.DoShowClipboard;
  529. begin
  530. end; {DoShowClipboard}
  531.  
  532. {----------}
  533. Function Checkboxes.DoCommand (
  534.     inCommand:        longint): Boolean;
  535. begin
  536.     DoCommand := true;
  537.     case inCommand of
  538.         cmdUndo:
  539.                 DoUndo;
  540.         cmdCut:
  541.                 DoCut;
  542.         cmdCopy:
  543.                 DoCopy;
  544.         cmdPaste:
  545.                 DoPaste;
  546.         cmdClear:
  547.                 DoClear;
  548.         cmdSelectAll:
  549.                 DoSelectAll;
  550.         cmdShowClipboard:
  551.                 DoShowClipboard;
  552.  
  553.         otherwise
  554.                 DoCommand := false;
  555.     end; {case}
  556. end;
  557.  
  558. end.
  559.